]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
scripting.js: small cleanups
authorOwen W. Taylor <otaylor@fishsoup.net>
Tue, 8 Mar 2011 23:51:15 +0000 (18:51 -0500)
committerOwen W. Taylor <otaylor@fishsoup.net>
Sat, 12 Mar 2011 00:21:07 +0000 (19:21 -0500)
- Fix missing trailing semicolons
- Catch when something results in metrics not being to avoid
  hard-to-debug JSON parse errors.

https://bugzilla.gnome.org/show_bug.cgi?id=644265

js/ui/scripting.js

index 2e38d1087581030c10e687840716ca1fbc8860e4..1fc583ea7c4676b5f63adec46935f1ecd13cdaa3 100644 (file)
@@ -246,8 +246,8 @@ function _collect(scriptModule, outputFile) {
         Shell.write_string_to_stream(out, '"events":\n');
         Shell.PerfLog.get_default().dump_events(out);
 
-        let monitors = global.get_monitors()
-        let primary = global.get_primary_monitor()
+        let monitors = global.get_monitors();
+        let primary = global.get_primary_monitor();
         Shell.write_string_to_stream(out, ',\n"monitors":\n[');
         for (let i = 0; i < monitors.length; i++) {
             let monitor = monitors[i];
@@ -266,7 +266,21 @@ function _collect(scriptModule, outputFile) {
         Shell.write_string_to_stream(out, ',\n"metrics":\n[ ');
         let first = true;
         for (let name in scriptModule.METRICS) {
-            let metric = scriptModule.METRICS[name]; 
+            let metric = scriptModule.METRICS[name];
+            // Extra checks here because JSON.stringify generates
+            // invalid JSON for undefined values
+            if (metric.description == null) {
+                log("Error: No description found for metric " + name);
+                continue;
+            }
+            if (metric.units == null) {
+                log("Error: No units found for metric " + name);
+                continue;
+            }
+            if (metric.value == null) {
+                log("Error: No value found for metric " + name);
+                continue;
+            }
 
             if (!first)
                 Shell.write_string_to_stream(out, ',\n  ');